function removeKNumber(arr, k) {
    let result = []
    for (let i = 0; i < arr.length; i++) {
        while (k && result.length && result[result.length - 1] > arr[i]) {
            result.pop()
            k--
        }
        result.push(arr[i])
    }

    while(result[0] === 0){
        result.shift()
    }
    console.log(result)
    let res = result.join("").substring(0, result.length - k)  // k 是变化的避免出现判断中情况没有执行，最后截取
    return res
}


console.log(removeKNumber([1, 2, 3, 4], 2))
console.log(removeKNumber([4,3,2,1], 2))